home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / dev / lang / sbp3_1e.lzh / CARTONS.PL < prev    next >
Text File  |  1991-10-31  |  2KB  |  73 lines

  1. /* From the book PROLOG PROGRAMMING IN DEPTH
  2.    by Michael A. Covington, Donald Nute, and Andre Vellino.
  3.    Copyright 1988 Scott, Foresman & Co.
  4.    Non-commercial distribution of this file is permitted. */
  5. /* Modified for Quintus Prolog by Andreas Siebert */
  6.  
  7. /* CARTONS.PL */
  8.  
  9. /*
  10.  * This is a set of production rules for a robot that
  11.  * stacks cartons in a warehouse. The rules have been
  12.  * translated into Prolog rules that can be used with
  13.  * the forward chaining inference engine in FCHAIN.PL.
  14.  */
  15.  
  16. rule(1) :- goal(stack([X,Y|Rest])),
  17.            fact(supports(X,Y)),
  18.                 then,
  19.            rg(stack([X,Y|Rest])),
  20.            ag(stack([Y|Rest])).
  21.  
  22. rule(2) :- goal(stack([X,Y|Rest])),
  23.            \+ fact(supports(X,_)),
  24.            \+ fact(supports(Y,_)),
  25.            fact(supports(Z,Y)),
  26.                 then,
  27.            rf(supports(Z,Y)),
  28.            af(supports(X,Y)),
  29.            rg(stack([X,Y|Rest])),
  30.            ag(stack([Y|Rest])).
  31.  
  32. rule(3) :- goal(stack([X,Y|_])),
  33.            fact(supports(X,Z)),
  34.            \+ (Y = Z),
  35.            \+ goal(remove(Z)),
  36.                 then,
  37.            ag(remove(Z)).
  38.  
  39. rule(4) :- goal(stack([_,X|_])),
  40.            fact(supports(X,Y)),
  41.            \+ goal(remove(Y)),
  42.                 then,
  43.            ag(remove(Y)).
  44.  
  45. rule(5) :- goal(remove(X)),
  46.            fact(supports(X,Y)),
  47.            \+ goal(remove(Y)),
  48.                 then,
  49.            ag(remove(Y)).
  50.  
  51. rule(6) :- goal(remove(X)),
  52.            \+ fact(supports(X,_)),
  53.            fact(supports(Y,X)),
  54.                 then,
  55.            rf(supports(Y,X)),
  56.            af(supports(floor,X)),
  57.            rg(remove(X)).
  58.  
  59. rule(7) :- goal(stack([X])),
  60.                 then,
  61.            rg(stack([X])).
  62.  
  63. /*
  64.  * Initial facts and goals for the carton stacking robot
  65.  */
  66.  
  67. fact(supports(floor,a)).
  68. fact(supports(floor,b)).
  69. fact(supports(b,c)).
  70. fact(supports(c,d)).
  71.  
  72. goal(stack([a,b,c,d])).
  73.